import { getAllCategory, selectDepart } from '@/api/category'
import { createTreeData } from "@ruifox-cms/utils"
/**
 * 模型字段的万能数据方法
 */
export const dataSourceList = [
    {"label": "栏目数据", "value": "category"},
    {"label": "科室列表", "value": "depart"}
]
export function getOptions(type, isTree=false, params={}) {
    switch (type) {
        // 栏目数据
        case 'category':
            return new Promise((resolve, reject) => {
                getAllCategory(params).then(res => {
                    if (isTree) {
                        resolve(createTreeData(res.data))
                    } else {
                        resolve(res.data)
                    }
                }).catch(err => {
                    reject(err)
                })
            })
            // 科室数据
        case 'depart':
            return new Promise((resolve, reject) => {
                selectDepart({siteId: localStorage.getItem('siteId')}).then(res => {
                    if (isTree) {
                        resolve(createTreeData(res.data, 'pid', 'id'))
                    } else {
                        resolve(res.data)
                    }
                }).catch(err => {
                    reject(err)
                })
            })
    }
}